﻿using Google.Protobuf.Reflection;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace LeafCore.Components.ElasticSearch
{
    public static class ElasticSearchExtensions
    {
        public static IServiceCollection AddES(this IServiceCollection services, Action<ElasticSearchOptions> esOptions)
        {
            var options = new ElasticSearchOptions();
            esOptions.Invoke(options);
            services.AddSingleton<IElasticSearchService>(sp => new ElasticSearchService(sp.GetRequiredService<ILoggerFactory>(), options));
            return services;
        }
    }
}
